#define _CRT_SECURE_NO_WARNINGS 1

class MinStack {
public:


    void push(int val)
    {
        s1.push(val);

        if (MinStack.empty())
        {
            MinStack.push(val);
        }
        else
        {
            if (val <= MinStack.top())
            {
                MinStack.push(val);
            }
        }

    }

    void pop()
    {
        if (!MinStack.empty() && s1.top() == MinStack.top())
        {
            MinStack.pop();
        }

        if (!s1.empty())
        {
            s1.pop();
        }

    }

    int top()
    {
        return s1.top();

    }

    int getMin()
    {
        return MinStack.top();
    }

private:

    stack<int> s1;
    stack<int> MinStack;
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */